﻿require.config({
  urlArgs: "version=20170501",
  paths: {
    'jquery': '../packages/jquery-2.14-min',
    'bootstrap': '../../bootstrap/js/bootstrap.min',
  },
  shim: {
    'bootstrap': {
      deps: ['jquery'],
      exports: 'bootstrap'
    }
  }
});




require(['jquery','bootstrap'], function ($) {

	var myChart = echarts.init(document.getElementById('content-right-classify1'));
  $('#graph-4001').click(function () {
  	drawGraph_4001();
	  $('#graph-show').modal('show');
  });
  $('#graph-4002').click(function () {
  	drawGraph_4002();
	  $('#graph-show').modal('show');
  });
  function drawGraph_4001() {
		/**
		 *ajax获取相应的数据 专利申请重点技术领域分布
		 */
		dataX = [];
	  	valueY = [];
		$.ajax({
		type : 'GET',
		url : '/draw/graph/4001',
		//data : jsonda,
		cache: false,
		async:false,
		//contentType: "application/json; charset=utf-8",
		dataType : 'json',
		success : function(res) {
			valueY = res.yValue;
			dataX = res.xAxis;
		},
		error : function(xml, err, throwInfo) {
			alert(err);
		}
		});
		myChart.clear();
		
		var symbolSize = 20;
		option = {
 		 title: {
     		 text: '专利申请重点技术领域分布'
 		 },
 		 tooltip: {
      		trigger: 'axis'
 		 },
 		 grid: {
     		 left: '3%',
     		 right: '4%',
     		 bottom: '3%',
     		 containLabel: true
 		 },
 		 toolbox: {
     		 feature: {
         	 	saveAsImage: {}
      		}
		  },
		  xAxis: {
     		  type: 'category',
     		  name:'IPC专利技术分类',
     		  nameLocation:'middle',
     		  nameGap: 21,
    		  data: dataX, 
    		  boundaryGap: ['10%', '10%'], 
    		  axisLabel: {
    	        	 textStyle: {fontSize: 12},
    	 interval: 0,  
    	   formatter: function (name) {
    	    return (name.length > 3 ? (name.slice(0,3)+"...") : name ); 
    	}
    	 
    	 
    	}
		  },
 		 yAxis: {
    		  type: 'value',
     		  name:'专利申请量/件',
     		  nameLocation:'middle',
     		  nameGap: 30
		  },
 		 series: [
    		  {
        	  name:'专利申请量/件',
       	  type:'bar',
        	  symbolSize: symbolSize,
        	  data: valueY,  
      }
  ]
};
		 myChart.setOption(option);
	}

function drawGraph_4002() {
	myChart.clear();
	var xAxisData = [];
	var data1 = [];
	var data2 = [];
	for (var i = 0; i < 100; i++) {
	    xAxisData.push('类目' + i);
	    data1.push((Math.sin(i / 5) * (i / 5 -10) + i / 6) * 5);
	    data2.push((Math.cos(i / 5) * (i / 5 -10) + i / 6) * 5);
	}
		option = {
			    title: {
			        text: '柱状图动画延迟'
			    },
			    legend: {
			        data: ['bar', 'bar2'],
			        align: 'left'
			    },
			    toolbox: {
			        // y: 'bottom',
			        feature: {
			            magicType: {
			                type: ['stack', 'tiled']
			            },
			            dataView: {},
			            saveAsImage: {
			                pixelRatio: 2
			            }
			        }
			    },
			    tooltip: {},
			    xAxis: {
			        data: xAxisData,
			        silent: false,
			        splitLine: {
			            show: false
			        }
			    },
			    yAxis: {
			    },
			    series: [{
			        name: 'bar',
			        type: 'bar',
			        data: data1,
			        animationDelay: function (idx) {
			            return idx * 10;
			        }
			    }, {
			        name: 'bar2',
			        type: 'bar',
			        data: data2,
			        animationDelay: function (idx) {
			            return idx * 10 + 100;
			        }
			    }],
			    animationEasing: 'elasticOut',
			    animationDelayUpdate: function (idx) {
			        return idx * 5;
			    }
			};
		 myChart.setOption(option);
	}
});